#!/usr/bin/perl

do "/home/robot/init.pl";


#### print out the Motor infor
foreach $motorName (sort keys %MOTOR_PATH){
	$speed=`cat $MOTOR_PATH{$motorName}/speed`;
	$maxsp=`cat $MOTOR_PATH{$motorName}/max_speed`;
	$position=`cat $MOTOR_PATH{$motorName}/position`;
	$duty_cycle=`cat $MOTOR_PATH{$motorName}/duty_cycle`;
	$stop_action=`cat $MOTOR_PATH{$motorName}/stop_action`;
	$time_sp=`cat $MOTOR_PATH{$motorName}/time_sp`;
	$state=`cat $MOTOR_PATH{$motorName}/state`;
	$class=$MOTOR_PATH{$motorName};
	write;
}
#### print out the SENSO info

print"\n  port   Name          Mode         value0  value1  value2  value3  value4  value5  value6  value7 class\n";
print"  ----- -------------- ------------ ------- ------- ------- ------- ------- ------- ------- ------- ------------------------------\n";

$~='STDOUT_S';
foreach $idx (sort keys %SENSOR_PATH){
	chop($mode=`cat $SENSOR_PATH{$idx}/mode`);
	for($i=0;$i<8;$i++){
		$valuefile="$SENSOR_PATH{$idx}/value$i";
		`cat $valuefile >/dev/null 2>&1`;
		if($? ==0){
			chop($value[$i]=`cat $valuefile`);
		}else{
			$value[$i]="-";
		}
	}

	write;
}



format STDOUT_TOP =
  Motor speed max_sp position duty_cycle count_per_rot stop_action time_sp state  class
  ----- ----- ------ -------- ---------- ------------- ----------- ------- ------ ------------------------------
.

format STDOUT =
  @<<<< @>>>> @>>>>>>> @>>>>>>>>> @>>>>>>>>>>>> @>>>>>>>>>> @>>>>>> @>>>>>> @>>>>> @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  $motorName, $speed ,$maxsp,$position,$duty_cycle,$count_per_rot,$stop_action,$time_sp,$state,$class
.

format STDOUT_TOP_S =
  Motor speed position duty_cycle count_per_rot stop_action time_sp state
  ----- ----- -------- ---------- ------------- ----------- ------- ------
.

format STDOUT_S =
  @<<<< @<<<<<<<<<<<<<< @<<<<<<<<<< @>>>>>> @>>>>>> @>>>>>> @>>>>>> @>>>>>> @>>>>>> @>>>>>> @>>>>>> @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  $idx, $SENSOR_NAME{$idx},$mode,$value[0],$value[1],$value[2],$value[3],$value[4],$value[5],$value[6],$value[7],$SENSOR_PATH{$idx} 
.
